/**
 * Apr 11, 2010
 */
package org.tomale.id.gis.renderers;

import javax.media.opengl.GL;

import org.tomale.id.gis.IRenderer;
import org.tomale.id.gis.MapElement;
import org.tomale.id.gis.elements.LineElement;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Point;

/**
 * @author ferd
 *
 */
public class LineRenderer implements IRenderer {

	/* (non-Javadoc)
	 * @see org.tomale.id.gis.IRenderer#getName()
	 */
	@Override
	public String getName() {
		return "Line Renderer";
	}

	/* (non-Javadoc)
	 * @see org.tomale.id.gis.IRenderer#getType()
	 */
	@Override
	public String getType() {
		return LineElement.class.toString();
	}

	/* (non-Javadoc)
	 * @see org.tomale.id.gis.IRenderer#render(javax.media.opengl.GL)
	 */
	@Override
	public void render(GL gl, final MapElement element) {
		if(element instanceof LineElement){
			LineElement line = (LineElement) element;
			
			gl.glBegin(GL.GL_LINE);
			
			Coordinate p1 = line.getPoint1().getCoordinate();
			Coordinate p2 = line.getPoint2().getCoordinate();
			
			gl.glVertex3d(p1.x, p1.y, p1.z);
			gl.glVertex3d(p2.x, p2.y, p2.z);
			
			gl.glEnd();
		}
	}

}
